package com.j1903.contorller;
import com.j1903.annotation.PassJwt;
import com.j1903.bean.Goods;
import com.j1903.bean.Goodscategory;
import com.j1903.bean.Lunbo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.j1903.util.JsonResult;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.j1903.service.GoodscategoryService;
import com.j1903.vo.TopCateCroup;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * <p>
 * 分类表 前端控制器
 * </p>
 *
 * @author fjj
 * @since 2021-12-13
 */
@RestController
@RequestMapping("/goodscategory")
@Slf4j
@CrossOrigin
public class GoodscategoryController {
    @Resource
    private GoodscategoryService goodscategoryService;
    @RequestMapping("/add")
    @PassJwt
    public JsonResult add(@RequestBody Goodscategory obj)
    {
    goodscategoryService.save(obj);
        return new JsonResult(200,"添加成功",obj.getId());
    }
    @RequestMapping("/deleted")
    @PassJwt
    public JsonResult Delete(@RequestBody Long id){
        Boolean hint=goodscategoryService.removeById(id);
        System.out.println(hint);
        if(hint)
        {
        return new JsonResult(200,"删除成功");
        }else
        {
        return new JsonResult(500,"删除失败");
        }

    }
    @RequestMapping("/update")
    @PassJwt
    public JsonResult Upd(@RequestBody Goodscategory obj){
        Boolean hint=goodscategoryService.saveOrUpdate(obj);
        if(hint)
        {
        return new JsonResult(200,"修改成功");
        }else
        {
        return new JsonResult(500,"修改失败");
        }

    }
    @RequestMapping("/list")
    @PassJwt
    public JsonResult list1(@RequestBody Goodscategory obj){
        List<Goodscategory> list=goodscategoryService.lists(obj);
        return new JsonResult(200,"查询成功",list);
    }
    @RequestMapping("/page/{curPage}/{pageRecords}")
    @PassJwt
    public JsonResult list2(@RequestBody Goodscategory obj,
        @PathVariable int curPage,
        @PathVariable int pageRecords
        ){
        IPage<Goodscategory> ipage=new Page<>(curPage,pageRecords);
        IPage<Goodscategory> page=goodscategoryService.pages(ipage,obj);
        return new JsonResult(200,"查询成功",page);
        }
//    @RequestMapping("/getTopGroup/{leftMenu}")
//    public JsonResult getTopGroup(@PathVariable("leftMenu") String leftMenu)
//    {
//        Map<String,List<TopCateCroup>> map=
//                goodscategoryService.getWithSub2(new Goodscategory(leftMenu));
//        System.out.println(map);
//        return new JsonResult(200,"查询成功",map);
//    }
    @RequestMapping("/getTopGroup")
    @PassJwt
    public JsonResult getTopGroup(String leftMenu)
    {
        Map<String,List<TopCateCroup>> map=
                goodscategoryService.getWithSub2(new Goodscategory(leftMenu));
        return new JsonResult(200,"查询成功",map);
    }
}

